﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ElectronicJournal
{
    public partial class Journals : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["id"] == null)
            {
                List<int> years = new DB.DbJournals().GetYears();
                string html = "<b style=\"font-size: 20px\">Номера журнала</b>";
                foreach (int year in years)
                {
                    List<DB.Item.ItemJournal> journals= new DB.DbJournals().GetJournalInYear(year);
                    string htmlString = "<div><table class=\"issue\" cellspacing=\"1\" cellpadding=\"0\"><tbody></tbody></table>";
                    htmlString = htmlString.Insert(htmlString.LastIndexOf("</tbody>"), String.Format("<tr><td style=\"border-right: #aaa 1px solid\">{0}<br><span>год</span></td></tr>", year));
                    for (int i = 0; i < journals.Count; i++)
                    {
                        htmlString = htmlString.Insert(htmlString.LastIndexOf("</tr>"), String.Format("<td onmouseover=\"selectCell(this)\" onmouseout=\"unselectCell(this)\" onclick=\"location.href=\'Journals.aspx?id={0}\'\"><a href=\"Journals.aspx?id={0}\">№ {1}</a></td>", journals[i].Id, journals[i].Number));
                    }
                    html += htmlString;
                }
                ContentLabel.Text = html;
                NavigationLabel.Text = "";
            }
            else
            {
                List<DB.Item.ItemPublication> publications = new DB.DbPublications().GetPublicationsInJournal(Request.Params["id"].ToString());
                DB.Item.ItemJournal journal = new DB.DbJournals().GetJournalById(Request.Params["id"].ToString());
                string html = String.Format("<table><tbody><tr><td><b style=\"font-size: 20px\">№ {0} за {1} год</b></td></tr></tbody></table>", journal.Number, journal.Year);
                foreach (DB.Item.ItemPublication publication in publications)
                {
                    html = html.Insert(html.LastIndexOf("</tbody>"), "<tr><td></td></tr>");
                    html = html.Insert(html.LastIndexOf("</td>"), String.Format("<div><div><b>{0}</b></div><div>{1}</div><div><a href=\"Abstract.aspx?rus={2}\">Резюме</a>|<a href=\"Abstract.aspx?eng={2}\">Abstract</a>|<a href=\"Abstract.aspx?file={2}\">Скачать</a></div></div>", publication.TitleRussian, new DB.DbPublications().GetPublicationAuthors(publication.Id), publication.Id));
                }
                ContentLabel.Text = html;
                NavigationLabel.Text = "<a href=\"Journals.aspx\">Номера журналов</a>";
            }
        }
    }
}